package com.ruoyi.project.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.project.domain.dto.KehuDTO;
import com.ruoyi.project.domain.entity.Kehu;
import com.ruoyi.project.mapper.KehuMapper;
import com.ruoyi.project.service.KehuService;
import org.springframework.stereotype.Service;

import lombok.AllArgsConstructor;

import java.util.List;

/**
 * (Kehu)表服务实现类
 *
 * @author yanweichao
 * @since 2025-06-25 14:26:21
 */
@Service
@AllArgsConstructor
public class KehuServiceImpl extends ServiceImpl<KehuMapper, Kehu> implements KehuService {

    protected LambdaQueryWrapper<Kehu> queryWrapper(KehuDTO param) {
        return new LambdaQueryWrapper<Kehu>()
                .like(StrUtil.isNotEmpty(param.getKeyword()), Kehu::getName, param.getKeyword())
                .orderByDesc(Kehu::getId);
    }

    @Override
    public Page<?> listPage(Page<Kehu> page, KehuDTO param) {
        return this.page(page, queryWrapper(param));
    }

    @Override
    public List<Kehu> queryList(KehuDTO param) {
        return this.list(queryWrapper(param));
    }

    @Override
    public boolean saveOrUpdate(KehuDTO param) {
        return param.isNew() ? this.save(param) : this.updateById(param);
    }
}
